<br/>

	<div class="row">
		<div class="col-md-4">
			<div class="widget box">
				<div class="widget-header">
					<h4><i class="icon-reorder"></i> Form Pembayaran Premi </h4>
				</div>
				<div class="widget-content">
				<div class="control-group">
					<label class="control-label">
					Jenis Asuransi
					<span class="required">*</span>
					</label>
					<div class="controls">
						<div class="input-group">
							<select class="form-control input-width-small" id="cb_jnsAsuransi">
								<option value="1">Health</option>
								<option value="2">Non Health</option>
							</select>
						</div>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">
					Nomor Polish 
					<span class="required">* (Akan menampilkan seluruh data premi lunas atau belum)</span>
					</label>
					<div class="controls">
						<div class="input-group">
							<input type="text" id="txt_no_polish" name="txt_no_polish"  class="form-control input-width-large">
							<input type="button" class="btn btn-default btn-warning" id="btn_show_cicil" value="Submit"> 
						</div>
					</div>
				</div>
				</div>
		</div>
	</div>
	</div>
	
	<div class="row">
					<div class="col-md-12">
						<div class="widget box">
							<div class="widget-header">
								<h4><i class="icon-reorder"></i> List Cicilan <code></code></h4>
								<div class="toolbar no-padding">
									<div class="btn-group">
										<span class="btn btn-xs widget-collapse"><i class="icon-angle-down"></i></span>
									</div>
								</div>
							</div>
							<div class="widget-content no-padding">
								<table id="tbl_cicilan" class="table table-striped table-bordered table-hover table-checkable table-responsive ">
									<thead>
										<tr>
											<th class="checkbox-column">
												<input type="checkbox" class="uniform" >
											</th>
											<th data-class="expand">Nominal</th>
											<th>Due Date</th>
											<th>Jumlah Bayar</th>
											<th>Status Bayar</th>
											<th>Action</th>
											<!-- <th data-class="expand">Nominal</th>
											<th>Premium</th>
											<th>Policy Cost</th>
											<th>Admin Broker</th>
											<th>Discount</th>
											<th>Adjusment</th>
											<th>Brokerage</th>
											<th>PPN</th>
											<th>PPH</th>
											<th>Due Date</th>
											<th>Status Bayar</th>
											<th>Action</th> -->
										</tr>
									</thead>
									<tbody id="isi_tabel">
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
				

<div id="modalProcess" class="modal fade in" style="display: none;" aria-hidden="false">
												<div class="modal-dialog" style="width:250px;">
													<div class="modal-content">
														<div class="modal-body">
															<div class="alert alert-info fade in" id="div_process">
															Waiting Process..
															</div>
															<div class="alert alert-success fade in" id="div_sukses" style="display:none;">
															Success Process..
															</div>
														</div>
														<div class="modal-footer">
															<button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
															
														</div>
													</div><!-- /.modal-content -->
												</div><!-- /.modal-dialog -->
											</div>

<script type="text/javascript">
$("#btn_show_cicil").click(function(e){
	var status = "";
	var action = "";
	var jml_bayar = "";
	var isi_tabel = "";
	$.ajax({
			type:"POST",
            url:"<?php echo Yii::app()->createUrl('/Pembayaran/showCicilan'); ?>",
			data:"txt_no_polish="+$("#txt_no_polish").val()+"&jns_asuransi="+$("#cb_jnsAsuransi").val(),
			dataType:"json",
            success:function(data){
				for(var i=0;i<data.jsonShowCicilan.length;i++){
					if(data.jsonShowCicilan[i].is_bayar == '1'){
						status = "<span class='label label-success'>Lunas</span>";
						action = "";
						jml_bayar = "<input type='text' class='form-control' name='txt_jml_bayar[]' id='txt_jml_bayar_"+data.jsonShowCicilan[i].id+"' readonly value='"+data.jsonShowCicilan[i].jml_bayar+"' >";
					}else{
						status = "<span class='label label-danger' id='span_"+data.jsonShowCicilan[i].id+"'>Belum</span>";
						action = '<button class="btn btn-xs btn-primary" id="btnbayar_'+data.jsonShowCicilan[i].id+'" onClick="bayarCicilan('+data.jsonShowCicilan[i].id+')">Bayar</button>';
						jml_bayar = "<input type='text' class='form-control' name='txt_jml_bayar[]' id='txt_jml_bayar_"+data.jsonShowCicilan[i].id+"' value='"+data.jsonShowCicilan[i].jml_bayar+"' >";
					}
					
					/*$("#tbl_cicilan").append("<tr>" +
					"<td>"+(parseInt(i)+1)+"</td>"+
					"<td>"+data.jsonShowCicilan[i].nominal+"</td>"+
					"<td>"+data.jsonShowCicilan[i].premium+"</td>"+
					"<td>"+data.jsonShowCicilan[i].policy_cost+"</td>"+
					"<td>"+data.jsonShowCicilan[i].admin_broker+"</td>"+
					"<td>"+data.jsonShowCicilan[i].discount+"</td>"+
					"<td>"+data.jsonShowCicilan[i].adjusment+"</td>"+
					"<td>"+data.jsonShowCicilan[i].brokerage+"</td>"+
					"<td>"+data.jsonShowCicilan[i].ppn+"</td>"+
					"<td>"+data.jsonShowCicilan[i].pph+"</td>"+
					"<td>"+data.jsonShowCicilan[i].due_date+"</td>"+
					"<td>"+status+"</td>"+
					"<td>"+action+"</td>"+
					"</tr>");*/
					isi_tabel += "<tr>" +
					"<td>"+(parseInt(i)+1)+"</td>"+
					"<td> <label id='txt_nominal_"+data.jsonShowCicilan[i].id+"'>"+data.jsonShowCicilan[i].nominal+"</label></td>"+
					"<td>"+data.jsonShowCicilan[i].due_date+"</td>"+
					"<td>"+jml_bayar+"</td>"+
					"<td>"+status+"</td>"+
					"<td>"+action+"</td>"+
					"</tr>";
					
				}
				$("#isi_tabel").html(isi_tabel);
				
			}
	});
});//end click

function bayarCicilan(id){
	$('#modalProcess').modal('show');
	$.ajax({
			type:"POST",
            url:"<?php echo Yii::app()->createUrl('/Pembayaran/bayarCicilan'); ?>",
			data:"id="+id+"&jml_bayar="+$("#txt_jml_bayar_"+id).val()+"&nominal="+$("#txt_nominal_"+id).text(),
			dataType:"json",
            success:function(data){
				if(parseInt($("#txt_jml_bayar_"+id).val()) >= parseInt($("#txt_nominal_"+id).text()) || parseInt($("#txt_jml_bayar_"+id).val()) >= ( parseInt($("#txt_nominal_"+id).text()) - 5000 )) {
					$("#span_"+id).hide();
					$("#btnbayar_"+id).hide();
					$("#div_sukses").show();
					$("#div_process").hide();
				}
				
				
				//location.href = "<?php echo Yii::app()->createUrl('/Pembayaran/index'); ?>";
			}
	});
}//end function
</script>